const db = uniCloud.database();

module.exports = class Utils {
	constructor(ctx) {

	}

	/**
	 * 删除云存储中的文件
	 * @param {arroy} file_id 删除文件的id
	 */
	async delFileFromCloud() {
		let willDelIds = []; //将要删除的数据id

		const cureentTime = new Date().getTime();

		const result = await db.collection('del-log').where({
				del_status: 1
			}).get();
		if (result.affectedDocs>0) {
			const ress = result.data;
			ress.forEach(item => {
				if (item.del_status == 1) {
					if (cureentTime - item.del_time >= 1000) { //864,000 十天
						willDelIds.push(item.del_data._id);
					}
				}
			});
			console.log(willDelIds);
			
			
			let res = await uniCloud.deleteFile({
				fileList: ["699f1f3b-d1c8-4b89-9f3f-c20c7a7fa2db","b0ab10b7-c6b7-4635-97e4-84e8d3fa6cf7"]
			});
			console.log(res);
			
			
			await db.collection('cloud-del-log').add({
				create_time: cureentTime,
				del_infos: willDelIds,
				del_log: res
			})
		}
		return;
	}
}
